#include <stdlib.h>
#include <stdio.h>
#include "string.h"

#include "bop2c.h"

unsigned char bo[2][3][2] = {{{0,1},{0,1},{1,1}},{{1,0},{1,1},{0,0}}};

int test()
{
    unsigned char a,b,c,e;
    int i, j, k;

    for(i=0; i<2; i++){
	for(j=0; j<3; j++){
	    for(k=0; k<2; k++){
		c = bo[i][j][k];
		fprintf(stdout, "%d", c);
	    }
	}
    }
    fprintf(stdout,"\n");
    
    e = 1;
    a = 1;
    b = 0;
    
    if (e) c = a;else c = b;

    fprintf(stdout, "%d\n", c);

    return(0);
}

void pipe01(char *s, int num, FILE *fic)
{
    int r = 0;
    unsigned char c = ' ';

    for( r=0; r<num; r++){
	c = fgetc(fic);
	if (c == '\n'){
	    fprintf(stderr, "PROTOCOLE PIPE 01 ERROR\n");
	    fprintf(stderr, "arite donnee : %d, attendue : %d\n", r, num);
	    fflush(stderr);
	    exit(1);    
	}
	s[r] = c;
    }

    while (c != '\n'){
	c = fgetc(fic);
    }
}

unsigned char input_node[2];
unsigned char output_node[3] = {'0','0','\0'};


void input(unsigned char *a, unsigned char *b){
    pipe01(input_node, 2, stdin);
    *a = (input_node[0] == '1');
    *b = (input_node[1] == '1');
}


void output(unsigned char a, unsigned char b){
    output_node[0] = a ? '1' : '0';
    output_node[1] = b ? '1' : '0';
    fprintf(stdout, "%s\n", output_node);
    fflush(stdout);
}



void test_input()
{
    char s[2];
    unsigned char a, b, s1, s2;
    
    input(&a, &b);
    output(a&&b, a||b);
}


int main(int argc, char **argv){
    int ncy = 1, index_cy = 0;
    if (argc>1) r = sscanf(argv[1], "%d", &ncy);

    while (index_cy < ncy){

	test_input();

	if(r)index_cy++;
    }

    return(0);
}
